/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
/**

 * Definition for singly-linked list.

 * public class ListNode {

 *     int val;

 *     ListNode next;

 *     ListNode() {}

 *     ListNode(int val) { this.val = val; }

 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }

 * }

 */

class Solution {

    public ListNode removeElements(ListNode head, int val) {

        ListNode newhead = new ListNode(0);

        newhead.next = head;

        ListNode cur = newhead;

        if (cur.next == null) {

            return null;

        }




        while(cur.next != null) {

            if (cur.next.val == val)

            {

                cur.next = cur.next.next;

            } else {

                cur = cur.next;

            }

        }

        return newhead.next;

    }}